package com.zx.zxojbackendquestion.controller.inner;

import com.zx.zxojbackendcommon.common.ErrorCode;
import com.zx.zxojbackendcommon.exception.BusinessException;
import com.zx.zxojbackendmodel.entity.Question;
import com.zx.zxojbackendmodel.entity.QuestionSubmit;
import com.zx.zxojbackendquestion.service.QuestionService;
import com.zx.zxojbackendquestion.service.QuestionSubmitService;
import com.zx.zxojbackendserviceclient.QuestionFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/inner")
@Slf4j
public class InnerQuestionController implements QuestionFeignClient {

    @Resource
    private QuestionService questionService;
    @Resource
    private QuestionSubmitService questionSubmitService;
    @GetMapping("/get/id")
    public Question getQuestionById(@RequestParam("questionId") Long questionId){
        return questionService.getById(questionId);
    }

    @GetMapping("/questionSubmit/get/id")
    public QuestionSubmit getQuestionSubmitById(@RequestParam("questionSubmitId") Long questionSubmitId){
        return questionSubmitService.getById(questionSubmitId);
    }

    @PostMapping("/questionSubmit/update")
    public void updateById(@RequestBody QuestionSubmit questionSubmitUpdate){
        boolean b = questionSubmitService.updateById(questionSubmitUpdate);
        if(!b){
            throw new BusinessException(ErrorCode.OPERATION_ERROR,"更新题目提交失败");
        }
    }
}
